#include <myheader.h>
#define FIFO_NAME "my_pipe"
#define FIFO_NAME_FILE "fifo_name_file"
/*Usage:进程1：参数：src_path, dest_path
 *进程a,通过管道将大数据文件循环进行传输，参数：文件的路径*/
int main(int argc, char *argv[])
{
    ARGC_CHECK(argc,2);

    //创建有名管道
    int mk_fifo_ret = mkfifo(FIFO_NAME,0666);
    ERROR_CHECK(mk_fifo_ret,-1,"mkfifo");
    //将管道名写入fifo_name_file文件
    int file_fd = open(FIFO_NAME_FILE,O_WRONLY);
    ERROR_CHECK(file_fd,-1,"fileopen");
    //先将文件截断为0
    int ftran_ret = ftruncate(file_fd,0);
    ERROR_CHECK(ftran_ret,-1,"fruncate");
    int pipe_name_len = strlen(FIFO_NAME);
       //注意长度要加1
    int write_ret = write(file_fd,FIFO_NAME,pipe_name_len + 1);
    ERROR_CHECK(write_ret,-1,"write_pipe_name_to_namefile");


    //打开管道
    int w_pipe_fd = open(FIFO_NAME,O_WRONLY);
    ERROR_CHECK(w_pipe_fd,-1,"open_pipe");
    //将文件名写入pipe
    //获取argv[1]的长度
    int file_name_len = strlen(argv[1]);
    int write_cnt = write(w_pipe_fd,argv[1],file_name_len + 1);
    printf("传送给pipe的文件名长度：%d",write_cnt);
    ERROR_CHECK(write_cnt,-1,"write_pipe");

    close(file_fd);
    close(w_pipe_fd);





    printf("Hello world\n");
    return 0;
}

